package com.wgy.day23.斗地主;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by pc on 2020/11/21 22:17
 * Description: LearningJava
 */
public class DouDiZhu {
    public static void main(String[] args) {
        //1.准备牌
        //定义一个集合用来存储54张牌,泛型使用String类型
        ArrayList<String> poker = new ArrayList<>();
        //定义2个数组,一个用来存储花色,另一个用来存储数字
        String[] colors = {"♥", "♠", "♣", "♦"};
        String[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
        //先把大王小王放到poker集合中
        poker.add("大王");
        poker.add("小王");
        //循环嵌套组装2个数组,让其中的52张牌也放入poker集合中
        for (String number : numbers) {
            for (String color : colors) {
              //  System.out.println(number+color);
                poker.add(number+color);
            }
        }
        System.out.println(poker);

        //2.洗牌
        //使用集合的工具类Collections中的方法,让集合内的元素随机排放
        Collections.shuffle(poker);

        //3.发牌
        //定义4个集合,存储玩家牌和底牌
        ArrayList<String> player01=new ArrayList<>();
        ArrayList<String> player02=new ArrayList<>();
        ArrayList<String> player03=new ArrayList<>();
        ArrayList<String> diPai=new ArrayList<>();
        for (int i = 0; i <poker.size() ; i++) {
            String p=poker.get(i);
            if(i>=51){
                diPai.add(p);
            }
            else if(i%3==0){
                player01.add(p);
            }
            else if(i%3==1){
                player02.add(p);
            }
            else if(i%3==2){
                player03.add(p);
            }
        }

        //4.看牌
        System.out.println("刘德华:"+player01);
        System.out.println("周星驰:"+player02);
        System.out.println("周润发:"+player03);
        System.out.println("底牌"+diPai);
    }
}
